<?php

namespace App\Modules\Web\Http\Controllers;

use App\Modules\Web\Http\Requests\Register;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use Illuminate\Support\Facades\Lang;


class RegisterController extends Controller
{


    protected function create(Register $request)
    {
        $dictionaries  = Hash::make('aaa');
        $request->setTrustedProxies(array('10.32.0.1/16'));
        $ip = $request->getClientIp();
        $user = User::create([
            'username' => self::return_username($dictionaries),
            'mobile' => $request['mobile'],
            'password' => bcrypt($request['password']),
            'last_visited_ip' => $ip,
        ]);

        if($user){
            return response()->Success([Lang::get('auth.register_success')]);
        }

    }

    function return_username($chars, $length = 8 ) {
        $username = 'User_';
        for ( $i = 0; $i < $length; $i++ )
    {
        $username .= substr($chars, mt_rand(0, strlen($chars) - 1 ), 1);
    }
    return $username;
}



}
